package org.baoping.demo.mq;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageConst;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author HeZeMin
 * @className MessageProducer
 * @description 消息-生产者
 * @date 2021/1/18 10:28
 */
@Slf4j
@EnableBinding({Source.class})// 绑定 output 消息通道
@Component
public class MessageProducer {
    @Autowired
    private Source source;

    public String send1(Map<String, Object> paramMap){
        MessageBuilder builder = MessageBuilder.withPayload(paramMap);
        builder.setHeader("tag", "tag-message");
        Message message = builder.build();
        source.output().send(message);
        return "success";
    }
    public String send2(Map<String, Object> paramMap){
        MessageBuilder builder = MessageBuilder.withPayload(paramMap);
        builder.setHeader("tag", "tag-demo");
        Message message = builder.build();
        source.output().send(message);
        return "success";
    }
}